package com.hunzi.controller.admin;

import com.hunzi.domain.AdminUser;
import com.hunzi.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin/adminuser")
public class AdminIoginController {

    @Autowired
    private AdminUserService adminUserService ;
    //管理员登录界面

    //实现登录的方法
    @RequestMapping("/login")
    public String login(String username , String password  , HttpServletRequest request , Model model){
        //1.获取用户输入的账号密码
        AdminUser adminUser = adminUserService.longinUser ( username, password );

        //2.判断管理员输入的账号密码是否正确
        if (adminUser != null){
            //管理员登录成功
            request.getSession ().setAttribute ( "adminUser" , adminUser );
            return  "redirect:/admin/" ;
        }else {

            request.setAttribute ( "error" , "请输入正确的用户名或密码" );
            return "admin/login";
        }



    }

}
